package com.shujia.dwd

import com.shujia.commom.SparkTool
import org.apache.spark.sql.{DataFrame, SparkSession}

object DwdFcjNwrsSellbargainMskDay extends SparkTool{


  /**
   * 抽象方法: 在子类中实现这个方法
   * import spark.implicits._
   * import org.apache.spark.sql.functions._
   *
   * @param spark ：spark环境
   * @param ds    ：分区
   */
  override def run(spark: SparkSession, ds: String): Unit = {
    import spark.implicits._
    import org.apache.spark.sql.functions._

    /**
     * 读取获取中的购房合同表
     * 按照分区读取数据
     *
     */

    val sellbargain: DataFrame = spark
      .table("ods.ods_t_fcj_nwrs_sellbargain")
      //分区过滤
      .where($"ds" === ds)


    //对原始的数据脱敏
    val resultDF: DataFrame = sellbargain.select(
      upper(md5($"id")) as "id",
      regexp_replace($"r_fwzl", "\\d", "*") as "r_fwzl",
      $"htydjzmj",
      $"tntjzmj",
      $"ftmj",
      $"time_tjba",
      $"htzj"
    )


    //保存数据，每天一个分区
    save(resultDF,s"/daas/motl/dwd/dwd_fcj_nwrs_sellbargain_msk_d/ds=$ds")
  }
}
